package cn.wzy.controller;

import cn.hutool.captcha.CaptchaUtil;
import cn.hutool.captcha.LineCaptcha;
import cn.wzy.common.Constant;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author nihaowzy
 * @date 2020/12/22 19:19
 */
@WebServlet("/checkCode.do")
public class CheckCodeServlet extends HttpServlet {

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        LineCaptcha lineCaptcha = CaptchaUtil.createLineCaptcha(170, 40, 4, 10);
        //将验证码放入session中
        String code = lineCaptcha.getCode();
        req.getSession().setAttribute(Constant.CHECK_CODE_KEY,code);

        lineCaptcha.write(resp.getOutputStream());
    }
}
